﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace UrlChecker.Setting
{
    public partial class AddGroup : Form
    {

        public AddGroup()
        {
            InitializeComponent();
        }

        public AddGroup(string gname)
        {
            InitializeComponent();
            this.Text = "修改分组";
            this.tbGroup.Text = gname;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.tbGroup.Text.Length == 0)
            {
                MessageBox.Show("请输入分组名称");
                return;
            }

            int rval = 0;

            if (this.Tag == null || string.IsNullOrEmpty(this.Tag.ToString())) rval = QT.SEO.Group.Add(this.tbGroup.Text);
            else rval = QT.SEO.Group.Update(this.Tag.ToString(), this.tbGroup.Text);

            switch (rval)
            {
                case 1:
                    MessageBox.Show("操作成功");
                    ((GroupManage)this.Owner).InitListView();
                    this.Tag = "";
                    this.Close();
                    break;
                case -2:
                    MessageBox.Show("分组名称[" + this.tbGroup.Text + "]已存在");
                    break;
                default:
                    MessageBox.Show("操作失败");
                    break;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
